﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;
using WatiN.Core;
using WatiN.Core.DialogHandlers;
using WatiN.Core.Exceptions;
using WatiN.Core.Interfaces;
using WatiN.Core.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using QAHelper.Common;
using Sentrana_QA.WatiNScript.SpoonByteTestScript;

namespace Sentrana_QA.WatiNScript.SpoonByteTestScript
{
    /// <summary>
    /// Summary description for RegistrationStepSix
    /// </summary>
    [TestClass]
    public class RegistrationStepSix
    {
        private static RestaurantCommon restaurantCommon = new RestaurantCommon();
                        
        #region Test Case #32

        public static string TestBRSS_B2_RR1_32(Browser window, DictionaryEntry[] tempTestData)
        {
            #region Local Parameters
            string result = null, temp = null;
            //Span span;
            Link editLink;
            #endregion

            #region Step 4 Validation                       

            #region Working at Step 6

            if (restaurantCommon.GoToStep6ByLogin(window))
            {
                #region Test Runs
                editLink = window.Link(Find.ByUrl(Properties.Settings.Default.RESTAURANT_URL.Trim()+"Register?fromReview=True"));
                editLink.Click();

                if (!window.ContainsText("Step 1 of 6: Enter Restaurant Operator Information"))
                    result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Restaurant User Information Edit link does not work properly";
                else
                {
                    result += Environment.NewLine+"User is redirected to the Step 1 properly.";

                    if (!window.TextField(Find.ById("FirstName")).Exists && window.TextField(Find.ById("FirstName")).Text == null)
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":First name field do not load properly.";
                    if (!window.TextField(Find.ById("LastName")).Exists && window.TextField(Find.ById("LastName")).Text == null)
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Last name field do not load properly.";
                    if (window.TextField(Find.ById("EmailAddress")).Exists && window.TextField(Find.ById("EmailAddress")).Text == null)
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Email Address field should not be loaded.";
                    if (window.TextField(Find.ById("Password")).Exists && window.TextField(Find.ById("Password")).Text == null)
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Password field should not be loaded.";
                    if (window.TextField(Find.ById("CaptchaText")).Exists && window.TextField(Find.ById("CaptchaText")).Text == null)
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Captcha Text field should not be loaded.";
                    if (window.Div(Find.ById("CaptchaImageDiv")).Exists)
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Captcha image should not be loaded.";
                    if (window.Button(Find.ByValue(ButtonsName.SaveButton)).Exists)
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Save & Continue button should not be present.";
                    if (!window.Button(Find.ByValue(ButtonsName.SubmitButton)).Exists)
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Submit button is missing.";
                }
                #endregion
            }
            else
                result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Step 6 page does not appear properly." + Environment.NewLine;
            #endregion

            #endregion

            return result;
        }
        #endregion

        #region Test Case #33

        public static string TestBRSS_B2_RR1_33(Browser window, DictionaryEntry[] tempTestData)
        {
            #region Local Parameters
            string result = null;
            Link editLink;
            bool flag = true;
            #endregion

            #region Step 4 Validation

            #region Working at Step 6

            if (restaurantCommon.GoToStep6ByLogin(window))
            {
                #region Test Runs

                #region Step 2
                editLink = window.Link(Find.ByUrl(Properties.Settings.Default.RESTAURANT_URL.Trim()+"RestaurantInformation?fromReview=True"));
                editLink.Click();

                if (!window.ContainsText("Step 2 of 6: Enter Restaurant Information"))
                    result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Restaurant Information Edit link does not work properly";
                else
                {
                    result += Environment.NewLine+"User is redirected to the Step 2 properly.";

                    //TODO: READ SYSCO ID

                    if (window.TextField(Find.ById("RestaurantName")).Text == null)
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Restaurant name not loaded properly.";
                    if (window.TextField(Find.ById("StreetAddress1")).Text == null)
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Restaurant Street Address 1 not loaded properly.";
                    if (window.TextField(Find.ById("Description")).Text == null)
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Description not loaded properly.";
                    if (window.TextField(Find.ById("City")).Text == null)
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":City not loaded properly.";
                    if (window.SelectList(Find.ById("State")).SelectedItem == "Select")
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":State not loaded properly.";
                    if (window.TextField(Find.ById("ZipCode")).Text == null)
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":ZipCode not loaded properly.";
                    if (window.TextField(Find.ById("primaryPhoneNumber")).Text == null)
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Primary Phone Number not loaded properly.";
                    if (window.TextField(Find.ById("RedemptionPhoneNumber")).Text == null)
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Redemption Phone Number not loaded properly.";
                    if (window.TextField(Find.ById("Website")).Text == null)
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Website not loaded properly.";
                    if (!window.Button(Find.ByValue(ButtonsName.SubmitButton)).Exists)
                    {
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Submit button not present.";
                        flag = false;
                    }
                    
                    //Check whether all Open & Close time loads properly or not
                    for (int i = 0; i < 7; i++)
                    {
                        if (window.SelectList(Find.ById("OperatingHourList[" + i + "]_StartDateTime")).SelectedOption.Value == "01:23 AM")
                            result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Open hour for day " + i + " is not loaded";
                        if (window.SelectList(Find.ById("OperatingHourList[" + i + "]_EndDateTime")).SelectedOption.Value == "01:23 AM")
                            result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Close hour for day " + i + " is not loaded";
                    }

                    window.Button(Find.ByValue(ButtonsName.SubmitButton)).Click();
                }
                #endregion

                #region Step 3
                if (!flag)
                {
                    window.Link(Find.ByUrl(Properties.Settings.Default.RESTAURANT_URL.Trim()+"/Logout")).Click();
                    restaurantCommon.GoToStep6ByLogin(window);
                    flag = true;
                }

                editLink = window.Link(Find.ByUrl(Properties.Settings.Default.RESTAURANT_URL.Trim() + "RestaurantDetails?fromReview=True"));
                editLink.Click();

                if (!window.ContainsText("Step 3 of 6"))
                    result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Restaurant Information Edit link does not work properly";
                else
                {
                    result += Environment.NewLine+"User is redirected to the Step 3 properly.";

                    //TODO: HOW TO COMPARE BETWEEN TWO EDIT LINK THAT POINT TO STEP 3 PAGE
                    //Debug the errors taking place in the commented code
                    Label label = window.Label(Find.ByClass("link_label").And(Find.By("onclick", "ShowPriomaryCuisineWindow()")));

                    if (label.Exists)
                    {
                        label.Click();

                        if (window.Div(Find.ById("PrimaryCuisineList")).Exists)
                        {
                            result += Environment.NewLine+"Primary cuisine list appeared properly.";
                            window.Button(Find.ByName("DoneButton")).Click();
                        }
                        else
                        {
                            result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Primary cuisine list not appeared.";
                        }
                    }                    
                        

                    if (!(window.RadioButton(Find.ById("Attire_Id") & Find.ByValue("1")).Checked || 
                        window.RadioButton(Find.ById("Attire_Id") & Find.ByValue("2")).Checked ||
                        window.RadioButton(Find.ById("Attire_Id") & Find.ByValue("3")).Checked))
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Attire not loaded properly.";

                    if (!(window.RadioButton(Find.ById("AcceptsCreditCard") & Find.ByValue("True")).Checked ||
                        window.RadioButton(Find.ById("AcceptsCreditCard") & Find.ByValue("False")).Checked))
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Accepts Credit Card not loaded properly.";

                    //if (!(window.RadioButton(Find.ById("PricingScale_Id") & Find.ByValue("1")).Checked ||
                    //    window.RadioButton(Find.ById("PricingScale_Id") & Find.ByValue("2")).Checked ||
                    //    window.RadioButton(Find.ById("PricingScale_Id") & Find.ByValue("3")).Checked ||
                    //    window.RadioButton(Find.ById("PricingScale_Id") & Find.ByValue("4")).Checked))
                    //    result += Environment.NewLine+"Pricing Scale not loaded properly.";

                    if (!(window.RadioButton(Find.ById("Reservation_Id") & Find.ByValue("1")).Checked ||
                        window.RadioButton(Find.ById("Reservation_Id") & Find.ByValue("2")).Checked ||
                        window.RadioButton(Find.ById("Reservation_Id") & Find.ByValue("3")).Checked))
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Reservation not loaded properly.";

                    //if (!(window.RadioButton(Find.ById("ProvidesDeliveryService") & Find.ByValue("True")).Checked ||
                    //    window.RadioButton(Find.ById("ProvidesDeliveryService") & Find.ByValue("False")).Checked))
                    //    result += Environment.NewLine+"Deliver not loaded properly.";

                    if (!(window.RadioButton(Find.ById("ProvidesTakeOutService") & Find.ByValue("True")).Checked ||
                        window.RadioButton(Find.ById("ProvidesTakeOutService") & Find.ByValue("False")).Checked))
                        result += Environment.NewLine+"Take-out not loaded properly.";

                    //if (!(window.RadioButton(Find.ById("ProvidesWaiterService") & Find.ByValue("True")).Checked ||
                    //    window.RadioButton(Find.ById("ProvidesWaiterService") & Find.ByValue("False")).Checked))
                    //    result += Environment.NewLine+"Table service not loaded properly.";

                    if (!(window.CheckBox(Find.ByName("Parkings") & Find.ByValue("1")).Checked ||
                        window.CheckBox(Find.ByName("Parkings") & Find.ByValue("2")).Checked ||
                        window.CheckBox(Find.ByName("Parkings") & Find.ByValue("3")).Checked ||
                        window.CheckBox(Find.ByName("Parkings") & Find.ByValue("4")).Checked))
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Parking not loaded properly.";

                    if (!(window.CheckBox(Find.ByName("Services") & Find.ByValue("1")).Checked ||
                        window.CheckBox(Find.ByName("Services") & Find.ByValue("2")).Checked ||
                        window.CheckBox(Find.ByName("Services") & Find.ByValue("3")).Checked ||
                        window.CheckBox(Find.ByName("Services") & Find.ByValue("4")).Checked))
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Services not loaded properly.";

                    if (!window.Button(Find.ByValue(ButtonsName.SubmitButton)).Exists)
                    {
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Submit button not present.";
                        flag = false;
                    }
                    window.Button(Find.ByValue(ButtonsName.SubmitButton)).Click();
                }
                #endregion

                #region Step 4
                if (!flag)
                {
                    window.Link(Find.ByUrl(Properties.Settings.Default.RESTAURANT_URL.Trim() + "Logout")).Click();
                    restaurantCommon.GoToStep6ByLogin(window);
                    flag = true;
                }

                editLink = window.Link(Find.ByUrl(Properties.Settings.Default.RESTAURANT_URL.Trim() + "UploadPhoto?fromReview=True"));
                editLink.Click();

                if (!window.ContainsText("Step 4 of 6"))
                    result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Restaurant Photo edit link does not work properly";
                else
                {
                    result += Environment.NewLine+"User is redirected to the Step 4 properly.";

                    
                    if (!window.Button(Find.ByValue(ButtonsName.SubmitButton)).Exists)
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Submit button not present.";

                    window.Button(Find.ByValue(ButtonsName.SubmitButton)).Click();
                }
                #endregion

                #endregion
            }
            else
                result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Step 4 page does not appear properly." + Environment.NewLine;
            #endregion

            #endregion

            return result;
        }
        #endregion

        #region Test Case #35

        public static string TestBRSS_B2_RR1_35(Browser window, DictionaryEntry[] tempTestData)
        {
            #region Local Parameters
            string result = null;
            bool flag = true;
            Link backLink;
            string server = "http://192.168.1.102";
            #endregion

            #region Step 4 Validation

            #region Working at Step 6

            if (restaurantCommon.GoToStep6ByLogin(window))
            {
                #region Test Runs

                backLink = window.Link(Find.ByText(ButtonsName.PreviousLink));
                backLink.Click();
                window.WaitForComplete();

                if (!window.ContainsText(StepHeaderText.Step4HeaderMessage))
                {
                    result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Previous Step link does not works properly.";
                    flag = false;
                }
                else
                    result += Environment.NewLine+"User redirects to Step 4 successfully.";

                if (flag)
                    window.Button(Find.ByValue(ButtonsName.SaveButton)).Click();

                window.Button(Find.ByValue(ButtonsName.PreviewSubmitButton)).Click();

                if (window.Url.ToString() != (Properties.Settings.Default.RESTAURANT_URL.Trim()+"RestaurantPageReview"))
                    result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":PREVIEW & SUBMIT button does not work.";
                else
                    result += Environment.NewLine+"PREVIEW & SUBMIT button works properly.";


                #endregion
            }
            else
                result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Step 6 page does not appear properly." + Environment.NewLine;
            #endregion

            #endregion

            return result;
        }
        #endregion

    }
}
